<?php

/**
 * This is the model class for table "employe".
 *
 * The followings are the available columns in table 'employe':
 * @property integer $id
 * @property integer $code
 * @property integer $personId
 * @property string $createdAt
 * @property string $updateAt
 * @property integer $createdBy
 * @property integer $updatedBy
 * @property integer $userId
 * @property string $nickname
 * @property string $startDate
 * @property string $educationLevel
 */
class Employe extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'employe';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('code, personId, createdAt, updateAt, createdBy, updatedBy, userId, nickname, startDate, educationLevel', 'required'),
			array('code, personId, createdBy, updatedBy, userId', 'numerical', 'integerOnly'=>true),
			array('nickname, educationLevel', 'length', 'max'=>100),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, code, personId, createdAt, updateAt, createdBy, updatedBy, userId, nickname, startDate, educationLevel', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations() {
		$relations = parent::relations();
		$relations['person'] = array(
			self::BELONGS_TO,
			'Person',
			'personId',
		);
		return $relations;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'code' => 'Code',
			'personId' => 'Person',
			'createdAt' => 'Created At',
			'updateAt' => 'Update At',
			'createdBy' => 'Created By',
			'updatedBy' => 'Updated By',
			'userId' => 'User',
			'nickname' => 'Nickname',
			'startDate' => 'Start Date',
			'educationLevel' => 'Education Level',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('code',$this->code);
		$criteria->compare('personId',$this->personId);
		$criteria->compare('createdAt',$this->createdAt,true);
		$criteria->compare('updateAt',$this->updateAt,true);
		$criteria->compare('createdBy',$this->createdBy);
		$criteria->compare('updatedBy',$this->updatedBy);
		$criteria->compare('userId',$this->userId);
		$criteria->compare('nickname',$this->nickname,true);
		$criteria->compare('startDate',$this->startDate,true);
		$criteria->compare('educationLevel',$this->educationLevel,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Employe the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
